package com.wzcl.app.controller;


import com.wzcl.app.dao.model.Attribute;
import com.wzcl.app.model.common.RVO;
import com.wzcl.app.model.dto.AttributeDto;
import com.wzcl.app.service.AttributeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@Log4j2
@RestController
@RequestMapping("/attribute")
@Api(value="规格属性controller",tags={"规格属性接口"})
public class AttributeController{

    @Autowired
    private AttributeService service;

    @ApiOperation("添加属性")
    @PostMapping("/add")
    public RVO<Attribute> addAttribute(@RequestBody @Valid AttributeDto attributeDto){
        Attribute attribute = service.addAttribute(attributeDto);
        return RVO.success(attribute);
    }

    @ApiOperation("删除属性")
    @PostMapping("/del")
    public RVO<Attribute> delAttribute(@RequestBody AttributeDto attributeDto){
        Attribute attribute = service.delAttributeById(attributeDto.getId());
        return RVO.success(attribute);
    }


    @ApiOperation("修改属性名属性")
    @PostMapping("/update")
    public RVO<Attribute> updateAttribute(@RequestBody @Valid AttributeDto attributeDto){
        Attribute attribute = service.updateAttribute(attributeDto);
        return RVO.success(attribute);
    }

    @ApiOperation("获取")
    @PostMapping("/getList")
    public RVO<List<Attribute>> getAttributeList(@RequestBody AttributeDto attributeDto){
        List<Attribute> list = service.getList(attributeDto);
        return RVO.success(list);
    }

}
